﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

#pragma once
#include "GnufBase.h"

namespace gnuf {

    class Item;
    class GNUF_BASE_EXPORT ItemPath
    {
        friend class Item;
    public:
        static const char Delimiter;
        static const char IndexDelimiter;
        static const char UniqueKeyDelimiter;

        explicit ItemPath(const std::string &);
        explicit ItemPath(const ItemPath &);

        // Return the path string.
        inline const std::string & str() const { return m_str; }

        // Return the path wstring.
        std::wstring wstr() const;

        // Split the path string to parts.
        std::vector<std::string> split() const;

        // Check if contain the part.
        int indexOf(const std::string & part) const;

        // Push a part at the end.
        ItemPath & push(const std::string &);

        // Push a part at the end.
        ItemPath & operator/(const char *);

        // Push an index at the end.
        ItemPath & operator+(unsigned long);

    private:
        void set(const Item *);
        ItemPath & add(const std::string &,
            const char delimiter = ItemPath::Delimiter,
            const bool toTail = true);
        std::string m_str;
    };

}
